package javase.javase01.exercise01;

import java.util.*;

/**
 * @author: Gan
 * @date 2021/4/14 0014 17:24
 * @description:
 **/
public class DemoCollection {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add('e');
        list.add('d');
        list.add('r');
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("hello");
        arrayList.add("java");
        arrayList.add("world");
        String[] s = new String[arrayList.size()];
        String[] arr = arrayList.toArray(s);
        System.out.println(arr.length);
        Collection c = new ArrayList();
        c.add("hello");
        c.add("world");
        c.add("武汉");
        Collection c1 = new ArrayList();
        c1.add("杭州");
        c1.add("阿里");
        System.out.println(c1.addAll(c));
        System.out.println(c1);
        System.out.println(c1.removeAll(c));
        System.out.println(c1);
        c1.clear();
        //返回集合的长度 int size();
        System.out.println(c1.size());
        boolean flag = c1.contains("阿里");
        System.out.println(flag);
        System.out.println(c1.isEmpty());
        Collection<String> coll = new ArrayList<>();
        coll.add("何");
        coll.add("志");
        coll.add("伟");
        Iterator it = coll.iterator();
        while (it.hasNext()) {
            String str = (String) it.next();
            System.out.println(str);
        }
        //左闭右开 11223344
        System.out.println(arrayList.subList(0, 2));
        System.out.println("=====linked=======");
        LinkedList link = new LinkedList();
        link.addFirst('w');
        link.addLast('e');
        System.out.println(link.getFirst());
        link.removeLast();
        System.out.println(link);
        System.out.println("===================");
        Deque stack = new LinkedList();
        stack.push("2");
        stack.push("w");
        stack.push("y");
        System.out.println(stack.peek());//窥视栈顶元素 y
        while (!stack.isEmpty()){
            String s1 = (String) stack.pop();
            System.out.print(s1+" ");
        }

    }

}
